package org.jeecg.modules.appuser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.util.Date.DateUtil;
import org.jeecg.modules.appuser.constant.PayTypeConstant;
import org.jeecg.modules.appuser.entity.TbUserSqtDetail;
import org.jeecg.modules.appuser.entity.TbUserWalletDetail;
import org.jeecg.modules.appuser.mapper.TbUserWalletDetailMapper;
import org.jeecg.modules.appuser.service.ITbUserWalletDetailService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Description: tb_user_wallet_detail
 * @Author: jeecg-boot
 * @Date:   2020-05-18
 * @Version: V1.0
 */
@Service
public class TbUserWalletDetailServiceImpl extends ServiceImpl<TbUserWalletDetailMapper, TbUserWalletDetail> implements ITbUserWalletDetailService {

    @Override
    public BigDecimal getUserWalletByToday(String user_id) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",user_id);
        queryWrapper.eq("pay_type", PayTypeConstant.PAYTYPE_INCOME);
        Date startDate=new Date(DateUtil.calcDate(0) + " 00:00:00");
        Date endDate=new Date(DateUtil.calcDate(0) + " 23:59:59");
        queryWrapper.between("create_time",startDate,endDate);
        List<TbUserWalletDetail> tbUserWalletDetailList=  this.baseMapper.selectList(queryWrapper);
        BigDecimal totalPayNumber=new BigDecimal(0);
        if(null!=tbUserWalletDetailList&&tbUserWalletDetailList.size()>0){

            for (TbUserWalletDetail tbUserWalletDetail : tbUserWalletDetailList) {
                BigDecimal payNumber= tbUserWalletDetail.getPayNumber();
                totalPayNumber=totalPayNumber.add(payNumber);
            }
        }
        return totalPayNumber;
    }
}
